package com.ruoyi.jjkc.jjkcsbzn.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.jjkc.jjkcsbzn.domain.Jjkcsbzn;
import com.ruoyi.jjkc.jjkcsbzn.domain.JjkcsbznFj;
import com.ruoyi.jjkc.jjkcsbzn.service.IJjkcsbznService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import java.io.InputStream;

import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 加计扣除申报指南Controller
 *
 * @author huacai
 * @date 2024-12-28
 */
@RestController
@RequestMapping("/jjkc/jjkcsbzn")
public class JjkcsbznController extends BaseController {
    @Resource
    private IJjkcsbznService jjkcsbznService;

    /**
     * 查询加计扣除申报指南列表
     */
    @PreAuthorize("@ss.hasPermi('jjkc:jjkcsbzn:list')")
    @GetMapping("/list")
    public TableDataInfo list(Jjkcsbzn jjkcsbzn) {
        startPage();
        List<Jjkcsbzn> list = jjkcsbznService.selectJjkcsbznList(jjkcsbzn);
        return getDataTable(list);
    }

    /**
     * 导出加计扣除申报指南列表
     */
    @PreAuthorize("@ss.hasPermi('jjkc:jjkcsbzn:export')")
    @Log(title = "加计扣除申报指南", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Jjkcsbzn jjkcsbzn) {
        List<Jjkcsbzn> list = jjkcsbznService.selectJjkcsbznList(jjkcsbzn);
        ExcelUtil<Jjkcsbzn> util = new ExcelUtil<Jjkcsbzn>(Jjkcsbzn.class);
        util.exportExcel(response, list, "加计扣除申报指南数据");
    }

    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<Jjkcsbzn> util = new ExcelUtil<Jjkcsbzn>(Jjkcsbzn.class);
        util.importTemplateExcel(response, "加计扣除申报指南数据");
    }

    /**
     * 导入数据
     */
    @Log(title = "加计扣除申报指南", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('jjkc:jjkcsbzn:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<Jjkcsbzn> util = new ExcelUtil<Jjkcsbzn>(Jjkcsbzn.class);
        InputStream inputStream = file.getInputStream();
        List<Jjkcsbzn> list = util.importExcel(inputStream);
        inputStream.close();
        int count = jjkcsbznService.batchInsertJjkcsbzn(list);
        return AjaxResult.success("导入成功" + count + "条信息！");
    }

    /**
     * 获取加计扣除申报指南详细信息
     */
    @PreAuthorize("@ss.hasPermi('jjkc:jjkcsbzn:query')")
    @GetMapping(value = "/{jjkcsbznId}")
    public AjaxResult getInfo(@PathVariable("jjkcsbznId") String jjkcsbznId) {
        return success(jjkcsbznService.selectJjkcsbznByJjkcsbznId(jjkcsbznId));
    }

    /**
     * 新增加计扣除申报指南
     */
    @PreAuthorize("@ss.hasPermi('jjkc:jjkcsbzn:add')")
    @Log(title = "加计扣除申报指南", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Jjkcsbzn jjkcsbzn) {
        return toAjax(jjkcsbznService.insertJjkcsbzn(jjkcsbzn));
    }

    /**
     * 修改加计扣除申报指南
     */
    @PreAuthorize("@ss.hasPermi('jjkc:jjkcsbzn:edit')")
    @Log(title = "加计扣除申报指南", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Jjkcsbzn jjkcsbzn) {
        return toAjax(jjkcsbznService.updateJjkcsbzn(jjkcsbzn));
    }

    /**
     * 删除加计扣除申报指南
     */
    @PreAuthorize("@ss.hasPermi('jjkc:jjkcsbzn:remove')")
    @Log(title = "加计扣除申报指南", businessType = BusinessType.DELETE)
    @DeleteMapping("/{jjkcsbznIds}")
    public AjaxResult remove(@PathVariable String[] jjkcsbznIds) {
        return toAjax(jjkcsbznService.deleteJjkcsbznByJjkcsbznIds(jjkcsbznIds));
    }

    /**
     * 获得加计扣除申报指南主键ID (UUID)
     */
    @GetMapping("/getJjkcSbZnId")
    public AjaxResult getJjkcSbZnId(){
        String getJjkcSbZnId = IdUtils.fastSimpleUUID();
        return success(getJjkcSbZnId);
    }

    /**
     * 新增附件
     */
    @PostMapping("/add/File/By/subId")
    public AjaxResult insertJjkcsbznFjById(@RequestBody JjkcsbznFj jjkcsbznFj){
        return toAjax(jjkcsbznService.insertJjkcsbznFjById(jjkcsbznFj));
    }

    /**
     * 根据ID查询附件列表
     */
    @GetMapping("/get/FileList/By/subId")
    public AjaxResult selectJjkcsbznFjList(String sId){
        JjkcsbznFj jjkcsbznFj = new JjkcsbznFj();
        jjkcsbznFj.setJjkcsbznId(sId);
        return AjaxResult.success(jjkcsbznService.selectJjkcsbznFjList(jjkcsbznFj));
    }

    /**
     * 删除加计扣除申报指南附件
     */
    @Log(title = "加计扣除申报指南附件", businessType = BusinessType.DELETE)
    @DeleteMapping("/fj/{fjIds}")
    public AjaxResult deleteJjkcsbznFjByFjIds(@PathVariable Integer[] fjIds)
    {
        return toAjax(jjkcsbznService.deleteJjkcsbznFjByFjIds(fjIds));
    }

}
